package com.kingyea.app.market.syncMission.service.impl;

import com.alibaba.fastjson.JSON;
import com.kingyea.app.market.condition.AllCondition;
import com.kingyea.app.market.syncMission.bean.SyncMission;
import com.kingyea.app.market.syncMission.dao.SyncMissionMapper;
import com.kingyea.app.market.syncMission.service.SyncMissionService;
import com.kingyea.app.market.utils.StateCode;
import com.kingyea.app.market.utils.page.PageInfo;
import com.kingyea.mobilepolice.system.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author
 * @version v1.0.0
 * @description SyncMission 实现类
 * @date Created in 2018-03-22 17:48:12
 */
@Service
@Transactional
public class SyncMissionServiceImpl implements SyncMissionService {

    private static final Logger LOGGER = LoggerFactory.getLogger(SyncMissionServiceImpl.class);

    @Resource
    private SyncMissionMapper syncMissionMapper;

    /**
     * 通过ID查找对象
     *
     * @return
     */
    @Override
    public SyncMission getById(String id) throws Exception {
        return this.syncMissionMapper.getById(id);
    }

    /**
     * 列表
     *
     * @param
     * @return
     */
    @Override
    public List<SyncMission> list(SyncMission syncMission) throws Exception {
        List<SyncMission> list = syncMissionMapper.list(syncMission);
        return list;
    }

    /**
     * 删除
     *
     * @param
     * @return
     */
    @Override
    public int deleteById(String id) throws Exception {
        syncMissionMapper.deleteById(id);
        return 1;
    }

    /**
     * 保存
     *
     * @param syncMission
     * @return
     */
    @Override
    public boolean save(SyncMission syncMission) {
        return syncMissionMapper.save(syncMission) == 1;
    }

    /**
     * 更新
     *
     * @param syncMission
     * @return
     */
    @Override
    public SyncMission update(SyncMission syncMission) throws Exception {
        syncMissionMapper.update(syncMission);
        return syncMission;
    }

    @Override
    public Object taskList(Map<String, Object> obj) throws Exception {
        // TODO Auto-generated method stub
        PageInfo.startPage(obj);
        return PageInfo.getPageInfo(syncMissionMapper.taskList(obj));
    }

    @Override
    public List<SyncMission> getPushResult(Map<String, Object> obj) throws Exception {
        // TODO Auto-generated method stub
        return syncMissionMapper.getPushResult(obj);
    }


    @Override
    public PageInfo<SyncMission> search(AllCondition condition) throws Exception {
        PageInfo.startPage(JSON.parseObject(JSON.toJSONString(condition), new HashMap<>().getClass()));
        return PageInfo.getPageInfo(syncMissionMapper.search(condition));
    }

    @Override
    public Object deletesByAppCode(String appCode) throws Exception {
        if (org.apache.commons.lang3.StringUtils.isBlank(appCode)) {
            throw new BusinessException(StateCode.NO_ARGUMENT_ERROR);
        }
        return syncMissionMapper.deletesByAppCode(appCode);
    }
}
